package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.constants.RedisConstants;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeItemUpsertReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author itcast
 * @since 2023-07-03
 */
@RestController("operationServeController")
@RequestMapping("operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Resource
    private IServeService serveService;

    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        PageResult<ServeResDTO> pageResult = serveService.page(servePageQueryReqDTO);
        return pageResult;
    }

    @PostMapping("/batch")
    @ApiOperation("添加区域服务项")

    public void saveBatch(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList) {
        serveService.saveBatch(serveUpsertReqDTOList);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改区域服务价格")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "price", value = "服务价格", required = true, dataType = "BigDecimal")
    })
    public void updatePrice(@PathVariable("id") Long id, @RequestParam("price") BigDecimal price) {
        serveService.updatePrice(id, price);
    }

    /**
     * 上架服务
     *
     * @param id 服务id
     */
    @PutMapping("/onSale/{id}")
    @ApiOperation("上架服务")
    public void onSale(@PathVariable("id") Long id) {
        serveService.onSale(id);
    }


}